﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iBuproModel;
using iBuproModel.Repositories.Interfaces;
using IBupro.Controllers.Classes;

namespace IBupro.Controllers
{
    /// <summary>
    /// This controller takes care about business logic suitable to Department principal role
    /// </summary>
    [HandleError]
    public class PrincipalController : CustomController
    {

        public PrincipalController()
        {
        }
        

        [Authorize(Roles="Principal")]
        public ActionResult Index()
        {
           return View();
        }

        [ChildActionOnly]
        [Authorize(Roles = "Principal")]
        public ActionResult AcceptedByLectorProjects()
        {
            IUserRepository userRepository = repositoryService.UserRepositoryCreateInstance();
            IDiplomProjectStateRepository projectState = repositoryService.DiplomProjectStateRepositoryCreateInstance();
            
            iBuproModel.User principal = userRepository.GetUserByUserName(User.Identity.Name);
            return View(principal.DepartmentPrincipalDiplomProjects.Where(p => p.DiplomProjectState.Id == projectState.GetLectorAcceptedProjectState().Id).ToList());
        }


        [ChildActionOnly]
        [Authorize(Roles = "Principal")]
        public ActionResult SubscribedProjects()
        {
            IUserRepository userRepository = repositoryService.UserRepositoryCreateInstance();
            IDiplomProjectStateRepository projectState = repositoryService.DiplomProjectStateRepositoryCreateInstance();

            iBuproModel.User principal = userRepository.GetUserByUserName(User.Identity.Name);
            return View(principal.DepartmentPrincipalDiplomProjects.Where(p => p.DiplomProjectState.Id == projectState.GetSubscribedProjectState().Id).ToList());
        }


    }
}
